package com.hardson.toolkit.swing;

import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;

import javax.swing.JFrame;

import com.hardson.toolkit.util.OSInfo;

import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
public class ScreenSize {

	/**
	 * 屏幕尺寸（像素分辨率）
	 * 注意：在linux(uos,deepin)操作系统，屏幕缩放不改变像素分辨率，dpi始终是96，始终得到的是设置的像素分辨率。
	 * 在windows操作系统，屏幕缩放直接改变像素分辨率，dpi默认是96,便会随着缩放率改变，得到的是缩放后的像素分辨率而不是设置的分辨率。
	 * 比如：设置的分辨率是3200*2000，放大到200%后，得到的像素分辨率是1600*1000
	 */
	private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

	// 获取屏幕边界
	private static Insets screenInsets = Toolkit.getDefaultToolkit()
			.getScreenInsets(new JFrame().getGraphicsConfiguration());
	private static int dpi = Toolkit.getDefaultToolkit().getScreenResolution();

	private ScreenSize(final int width, final int height) {
	}

	public static int getScreenWidth() {
		return screenSize.width;
	}

	public static int getScreenHeight() {
		return screenSize.height;
	}

	public static Dimension getScreenSize() {
		return getScreenSize(0);
	}

	public static Dimension getOriScreenSize() {
		if (OSInfo.isWindows()) {
			int width = screenSize.width * dpi / 96;
			int height = screenSize.height * dpi / 96;
			return new Dimension(width, height);
		}
		return getScreenSize(0);
	}

	public static Dimension getScreenSize(final int heightOffset) {
		return new Dimension(screenSize.width, screenSize.height - heightOffset);
	}

	public static int getTaskbarHeight() {
		return screenInsets.bottom;
	}

	public static Dimension getDefaultFullScreenDialogSize() {
		return getScreenSize(ScreenSize.getTaskbarHeight());
	}

	public static int getScreenResolution() {
		return dpi;
	}
}
